/*
 * Copyright (c) 2017 22420103@QQ.COM 版权所有
 */
package com.lehe.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lehe.dao.IndexDao;
import com.lehe.dao.PayRecordDao;
import com.lehe.entry.IndexDto;
import com.lehe.entry.UserInfoDto;
import com.lehe.entry.UserPayDto;
import com.lehe.service.impl.UserInfoService;

@Controller
@RequestMapping("wx")
public class WeixinWebController extends Basecontroller{
	
	@Autowired
	IndexDao indexDao;

	@Autowired
    private UserInfoService userInfoService;
	
	@Autowired
	PayRecordDao payRecordDao;
	
	@RequestMapping("pay")
	public String pay(){
		return "user/pay";
	}
	
	@RequestMapping("auth")
	public String auth(){
		return "user/auth";
	}
	
	@RequestMapping("payResult")
	public String payResult(String btime,String etime,Model m){
		IndexDto dto = new IndexDto();
		UserInfoDto u = userInfoService.queryUserInfo(this.getUserId(), null);
		
		if(u != null){
			dto.setNickName(u.getNickName());
		}
		
		if(btime != null && btime.trim().equals("")){
			btime = null;
		}
		
		if(etime != null && etime.trim().equals("")){
			etime = null;
		}
		
		dto.setUserId(this.getUserId());
		dto.setAgentID(this.getAgentId());
		dto.setBtime(btime);
		dto.setEtime(etime);
		dto.setMyPayCount(payRecordDao.queryUserPayCount(dto.getUserId(),btime,etime));
		dto.setMyPlayerPayCount(payRecordDao.queryUserPlayerPayCount(dto.getAgentID(),btime,etime));
		dto.setMyAngentPayCount(payRecordDao.queryUserAngentPayCount(this.getAgentId(),btime,etime));
		m.addAttribute("result", dto);
		
		return "user/payResult";
	}
	
	@RequestMapping("payAgentDetailList")
	public String payAgentDetailList(Long agentId,String btime,String etime,Model m){
		if(agentId == null){
			agentId = this.getAgentId();
		}
		m.addAttribute("btime", btime);
		m.addAttribute("etime", etime);
		m.addAttribute("agentId", agentId);
		return "user/agentPayDetailList";
	}
	
	
	@RequestMapping("playerPayDetailList")
	public String playerPayDetailList(String btime,String etime,Model m){
		m.addAttribute("btime", btime);
		m.addAttribute("etime", etime);
		return "user/playerPayDetailList";
	}
	
	@RequestMapping("userPayDetailList")
	public String userPayDetailList(Long userId,String btime,String etime,Model m){
		m.addAttribute("btime", btime);
		m.addAttribute("etime", etime);
		if(userId == null){
			userId = this.getUserId();
		}
		m.addAttribute("userId", userId);
		return "user/userPayDetailList";
	}
	
	@RequestMapping("userPayDetailListData")
	@ResponseBody
	public List<UserPayDto> userPayDetailListData(Long userId,String btime,String etime,Integer page,Integer pagesize){
		List<UserPayDto> result = null;
		if(userId == null){
			result = payRecordDao.queryUserPayDetail(this.getUserId(),btime,etime,page,pagesize);
		}else{
			result = payRecordDao.queryUserPayDetail(userId,btime,etime,page,pagesize);
		}
		return result;
	}
	
	@RequestMapping("playerPayDetailListData")
	@ResponseBody
	public List<UserPayDto> playerPayDetailListData(String btime,String etime,Integer page,Integer pagesize){
		List<UserPayDto> result = null;
		result = payRecordDao.queryUserPlayerPayDetail(this.getAgentId(),btime,etime,page,pagesize);
		return result;
	}
	
	@RequestMapping("payAgentDetailListData")
	@ResponseBody
	public List<UserPayDto> payAgentDetailListData(Long agentId,String btime,String etime,Integer page,Integer pagesize){
		List<UserPayDto> result = null;
		if(agentId == null){
			result = payRecordDao.queryUserAngentPayDetail(this.getAgentId(),btime,etime,page,pagesize);
		}else{
			result = payRecordDao.queryUserAngentPayDetail(agentId,btime,etime,page,pagesize);
		}
		return result;
	}
}
